﻿using System;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BusinessObjects.BO_GetObjects;
using DigiLib;

public partial class controls_admin_CategoryAdd : Admin_Controls_Base
{
    protected void Page_Load(object sender, EventArgs e)
    {
        base.removeHGC(divMessage);
        if (!IsPostBack)
        {
            try
            {
                bindDDL(ddlContentType, BO_portal_content_types.SelectAll(1), "DESCRIPTION", "CONTENT_TYPE_ID");
                bindDDL(ddlParent, BO_portal_categories.Inside(0), "FULL_CATEGORY_NAME", "CATEGORY_ID");
                txtSortDisplay.Text = SqlUtils.GetNextOrderDisplay("portal_categories").ToString();
                ddlParent.SelectedValue = Category_ID.ToString();
            }
            catch (Exception ex) { divMessage.InnerHtml = MessageBox.Error("Lỗi", "Phát sinh lỗi như sau: " + ex.Message); }
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        try
        {
            string categoryName = txtFullCategoryName.Text.Trim();
            string categoryNameEng = txtUrl.Text.Trim();
            string categoryDescription = txtFullCategoryDescription.Text.Trim();
            string categoryDescriptionEng = "";
            int sortdisplay = Convert.ToInt32(txtSortDisplay.Text.Trim());
            int parent = Convert.ToInt32(ddlParent.SelectedValue);
            int content_type = Convert.ToInt32(ddlContentType.SelectedValue);
            bool is_menu = cboMenu.Checked;
            string filename = base.Upload("categories", String.Empty, fupIcon, divMessage, false);
            string result = BO_portal_categories.Insert(
                    parent, content_type,
                    string.Empty, string.Empty, categoryName,
                    categoryNameEng, filename, string.Empty, string.Empty, categoryDescription, categoryDescriptionEng, is_menu,
                    0, sortdisplay,
                    DateTime.Now, Administrator.USER_NAME,
                    DateTime.Now, Administrator.USER_NAME, 1);
            if (result.Equals("0")) divMessage.InnerHtml = MessageBox.Error("Thông Báo", "Chưa thực hiện được, vui lòng trở lại sau !");
            else
            {
                divMessage.InnerHtml = MessageBox.Success("Thông Báo", "Thực hiện thành công !");
            }
        }
        catch (Exception ex)
        {
            divMessage.InnerHtml = MessageBox.Error("Lỗi", "Phát hiện lỗi: <br />" + ex.Message);
        }
    }
}
